import API from './api'
const getCurrentCity = () => {
  let localCity = JSON.parse(localStorage.getItem('fh_city'))
  if (!localCity) {
    return new Promise((resolve, reject) => {
      const curCity = new window.BMap.LocalCity()
      curCity.get(async res => {
        try {
          const result = await API.get(`/area/info?name=${res.name}`)
          localStorage.setItem('fh_city', JSON.stringify(result))
          resolve(result)
        } catch (e) {
          reject(e)
        }
      })

    })
  } else {
    return Promise.resolve(localCity)
  }
}
const BASE_URL = process.env.REACT_APP_URL
export { BASE_URL, getCurrentCity }